//index.js
//获取应用实例
const app = getApp()
var utils = require('../../utils/util.js');
Page({
    data: {
		islogin:false
	},

	onShow: function() {
        var that = this;
        //登录后获取店铺列表
        app.makeLogin((res) => {
            this.memberInfo();
			this.sliderList();
			this.getLetterClass();
        });
    },
    //获取用户信息
    memberInfo: function(e) {
        var that = this;
        utils.http("/api/v1/member/index", {}, function(res) {
          //  console.log(res)
			that.setData({
				info:res.datas
			})
        })
    },
    //幸运抽奖
    onLuckyDrawTap: function(e) {
        wx.navigateTo({
            url: "../luckydraw/luckydraw"
        })
    },


	//轮播图跳转
	sliderTap: function (e) {
		console.log(e)
		if (e.currentTarget.dataset.type == 0) {
			wx.navigateTo({
				url: '../sliderdetail/sliderdetail?id=' + e.currentTarget.dataset.id
			})
		} else {

			var posall = [];
			for (var i in this.data.slider) {
				posall.push(this.data.slider[i].image)
			}
			console.log(posall);
			wx.previewImage({
				current: e.currentTarget.dataset.src, // 当前显示图片的http链接
				urls: posall// 需要预览的图片http链接列表

			})

		}
	},



    //投标保函
    //履约保函/预付款保函/农民工保函
    onIndemnityTap: function(e) {
		var that=this;
		if (that.data.info.nickname==""){
			that.setData({
				islogin:true
			})
			
			return false;
		}
		if (e.currentTarget.dataset.id == 1) {
            //投标保函
            wx.navigateTo({
				url: "../bidbond/bidbond?id=" + e.currentTarget.dataset.id
            })
        } else {
            //履约保函/预付款保函/农民工保函
            wx.navigateTo({
				url: '../indemnity/indemnity?id=' + e.currentTarget.dataset.id,
            })
        }

        app.globalData.type = e.currentTarget.dataset.id;
    },
	//获取用户信息
	onGotUserInfo:function(e){
		var that=this;
		utils.showLoading("正在登陆")
		if (e.detail.errMsg =="getUserInfo:ok"){
			utils.http("/api/v1/member/member_modify",{
				nickname: e.detail.userInfo.nickName,
				sex: e.detail.userInfo.gender,
				avatar: e.detail.userInfo.avatarUrl
			},function(res){
				utils.hideLoading();
				if (res.state==1){
					that.memberInfo();
					that.setData({
						islogin: false
					})
				}
				
			})
		}
	},
	//首页轮播图
	sliderList:function(e){
		var that=this;
		utils.http("/api/v1/common/slider_list",{
			model:0
		},function(res){
			if (res.state==1){
				that.setData({
					slider: res.datas
				})
			}
			
		})
	},

	//获取保函类型 列表
	getLetterClass:function(e){
		var that = this;
		utils.showLoading()
		utils.http("/api/v1/common/get_letter_class", {}, function (res) {
			utils.hideLoading();
			if (res.state == 1) {
				
				that.setData({
					letter: res.datas
				})
			}

		})
	},
	onInspectTap:function(e){
		wx.navigateTo({
			url: '../inspect/inspect',
			success: function(res) {},
			fail: function(res) {},
			complete: function(res) {},
		})
	},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})